package com.github.baichuan.application.scaffold.rest.dto.app;

import com.github.baichuan.application.scaffold.rest.domain.app.AppVersion;
import com.github.baichuan.mapping.BeanMapper;
import com.github.baichuan.mapping.Mapping;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

@Schema(title = "APP版本")
@Getter
public class AppVersionTableView {
    @Mapping
    private int id;

    @Schema(title = "版本号")
    @Mapping
    private String version;

    @Schema(title = "升级模式")
    @Mapping
    private String upgradeMode;

    @Schema(title = "发布日期")
    @Mapping(format = "yyyy-MM-dd HH:mm")
    private String releaseTime;

    @Schema(title = "升级文件")
    private String fileUrl;

    public static class Mapper {
        public AppVersionTableView map(AppVersion version) {
            AppVersionTableView view = BeanMapper.map(version, AppVersionTableView.class);
            view.fileUrl =  "/api/app-release-file/" + version.getApp().getCode() + "/" + version.getFile();
            return view;
        }
    }
}
